package com.morning.dp.tools.demo;

import com.morning.dp.tools.dp.DPWrapperChain;

/**
 * WrapperChainDemo
 *
 * @author @阿秋
 * @date 2021/3/19
 */
public class WrapperChainDemo {
    public static void main(String[] args) {
        String result = DPWrapperChain.createWrapperChain(String.class)
                .withParam("testParam1", "1234")
                .withParam("testParam2", "12345")
                .addWrapper(WrapperChainDemo::wrapperLog1)
                .addWrapper(WrapperChainDemo::wrapperLog2)
                .addWrapper(WrapperChainDemo::wrapperLog3)
                .invoke(WrapperChainDemo::originInvoke);
        System.out.println(result);
    }
    
    private static String originInvoke() {
        return "[origin invoke]";

    }

    private static String wrapperLog3(DPWrapperChain.ChainContext<String> voidChainContext) {
        String testParam1 = voidChainContext.getParam("testParam1", String.class);
        System.out.println(testParam1);
        return "log3_" + voidChainContext.execute() + "_log3";
    }

    private static String wrapperLog2(DPWrapperChain.ChainContext<String> voidChainContext) {
        return "log2_" + voidChainContext.execute() + "_log2";
    }

    private static String wrapperLog1(DPWrapperChain.ChainContext<String> voidChainContext) {
        return "log1_" + voidChainContext.execute() + "_log1";
    }

}
